var returnUrl = "/"; //返回地址

//用户登录
function login() {
    var loginForm = document.forms["loginForm"];

    var accountName = loginForm.elements["accountName"].value;
    var password = loginForm.elements["password"].value;
    var verifyCode = loginForm.elements["verifycode"] ? loginForm.elements["verifycode"].value : undefined;
    var isRemember = loginForm.elements["isremember"] ? loginForm.elements["isremember"].checked ? 1 : 0 : 0;

    if (!verifyLogin(accountName, password, verifyCode)) {
        return;
    }

    var parms = new Object();
    parms["accountname"] = accountName;
    parms["password"] = password;
    parms["verifycode"] = verifyCode;
    parms["isremember"] = isRemember;
    var action = loginForm.getAttribute("action");
    $.post(action, parms, loginResponse);
}

//验证登录
function verifyLogin(accountName, password, verifyCode) {
    if (accountName.length == 0) {
        layer.msg("请输入账户名");
        return false;
    } else {

    }
    if (password.length == 0) {
        layer.msg("请输入密码");

        return false;
    }
    if (verifyCode != undefined && verifyCode.length == 0) {
        layer.msg("请输入验证码");

        return false;
    }
    return true;
}

//处理登录的反馈信息
function loginResponse(data) {
    var result = data.code;
    if (result >= 0) {
        window.location.href = data.url;
    }
    else {
        layer.msg(data.message);
    }
}

//刷新验证码
function reloadimg() {
    document.getElementById("verifyImage").src = base + '/account/captcha.jpg?time=' + new Date();
}

